﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;
using ASPNETPerformance.App_BusinessLogic.Helpers;
using ASPNETPerformance.App_BusinessLogic.Utils;

namespace ASPNETPerformance.UserControls {
    public partial class Part4 : BaseUserControl {
        protected void Page_Load( object sender, EventArgs e ) {
            if ( !this.Page.IsPostBack ) {
                BindPart4();
            }
        }

        private void BindPart4() {
            this.cbEnableHttpCompression.Checked = CommonHelper.GetCookieBool( "IsHttpCompression" );
            this.cbEnableWhitespaceFilter.Checked = CommonHelper.GetCookieBool( "IsWhitespaceFilter" );
            this.cbEnableViewStateFilter.Checked = CommonHelper.GetCookieBool( "IsViewStateFilter" );
            this.cbEnableNamingContainerFilter.Checked = CommonHelper.GetCookieBool( "IsNamingContainerFilter" );
        }

        protected void BtnPart4_Click( object sender, EventArgs e ) {
            SaveInfo();

            this.lblPart4Result.Text = "保存成功。";
        }

        public void SaveInfo() {
            CommonHelper.SetCookie( "IsHttpCompression",
              this.cbEnableHttpCompression.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsWhitespaceFilter",
               this.cbEnableWhitespaceFilter.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsViewStateFilter",
               this.cbEnableViewStateFilter.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsNamingContainerFilter",
             this.cbEnableNamingContainerFilter.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );
        }
    }
}